/**
 * 统一响应码配置
 * 所有响应码都在这里定义，整个项目统一使用
 */

export enum ResponseCode {
  // 成功
  SUCCESS = 200,
  
  // 客户端错误 4xx
  BAD_REQUEST = 400,
  UNAUTHORIZED = 401,
  FORBIDDEN = 403,
  NOT_FOUND = 404,
  METHOD_NOT_ALLOWED = 405,
  CONFLICT = 409,
  TOO_MANY_REQUESTS = 429,
  
  // 服务器错误 5xx
  INTERNAL_SERVER_ERROR = 500,
  BAD_GATEWAY = 502,
  SERVICE_UNAVAILABLE = 503,
  
  // 业务错误 1000+
  USER_NOT_FOUND = 1001,
  USER_ALREADY_EXISTS = 1002,
  INVALID_PASSWORD = 1003,
  TOKEN_EXPIRED = 1004,
  TOKEN_INVALID = 1005,
  PERMISSION_DENIED = 1006,
  MEMBER_NOT_FOUND = 1007,
  MEMBER_ALREADY_EXISTS = 1008,
  LEVEL_NOT_FOUND = 1009,
  DATABASE_ERROR = 1010,
  REDIS_ERROR = 1011,
  BLOG_NOT_FOUND = 1012,
  BLOG_ALREADY_EXISTS = 1013,
}

export const ResponseCodeMsg: Record<ResponseCode, string> = {
  [ResponseCode.SUCCESS]: '成功',
  [ResponseCode.BAD_REQUEST]: '请求参数错误',
  [ResponseCode.UNAUTHORIZED]: '未授权，请先登录',
  [ResponseCode.FORBIDDEN]: '禁止访问',
  [ResponseCode.NOT_FOUND]: '资源不存在',
  [ResponseCode.METHOD_NOT_ALLOWED]: '请求方法不允许',
  [ResponseCode.CONFLICT]: '资源冲突',
  [ResponseCode.TOO_MANY_REQUESTS]: '请求过于频繁，请稍后再试',
  [ResponseCode.INTERNAL_SERVER_ERROR]: '服务器内部错误',
  [ResponseCode.BAD_GATEWAY]: '网关错误',
  [ResponseCode.SERVICE_UNAVAILABLE]: '服务不可用',
  [ResponseCode.USER_NOT_FOUND]: '用户不存在',
  [ResponseCode.USER_ALREADY_EXISTS]: '用户已存在',
  [ResponseCode.INVALID_PASSWORD]: '密码错误',
  [ResponseCode.TOKEN_EXPIRED]: 'Token已过期',
  [ResponseCode.TOKEN_INVALID]: 'Token无效',
  [ResponseCode.PERMISSION_DENIED]: '权限不足',
  [ResponseCode.MEMBER_NOT_FOUND]: '会员不存在',
  [ResponseCode.MEMBER_ALREADY_EXISTS]: '会员已存在',
  [ResponseCode.LEVEL_NOT_FOUND]: '等级不存在',
  [ResponseCode.DATABASE_ERROR]: '数据库错误',
  [ResponseCode.REDIS_ERROR]: 'Redis错误',
  [ResponseCode.BLOG_NOT_FOUND]: '博客不存在',
  [ResponseCode.BLOG_ALREADY_EXISTS]: '博客已存在',
};

